package yz.cp.back.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yz.cp.back.common.utils.PageKit;
import yz.cp.back.common.vo.SearchVo;
import yz.cp.back.s.entity.SysMessage;
import yz.cp.back.s.service.ISysMessageService;

@Service
public class MessageManage {

    @Autowired
    private ISysMessageService sysMessageService;

    public IPage<SysMessage> findByCondition(SysMessage sysMessage, SearchVo searchVo) {
        QueryWrapper<SysMessage> wrapper = new QueryWrapper<>();
        IPage<SysMessage> page = PageKit.buildPage(searchVo, wrapper);

        wrapper.lambda().like(StringUtils.isNotBlank(sysMessage.getTitle()), SysMessage::getTitle, sysMessage.getTitle())
                .like(StringUtils.isNotBlank(sysMessage.getContent()), SysMessage::getContent,sysMessage.getContent())
                .eq(sysMessage.getType()!=null, SysMessage::getType,sysMessage.getType());
        //创建时间
        if(searchVo.getStartDate()!=null&&searchVo.getEndDate()!=null){
           wrapper.lambda().between(SysMessage::getCreateTime,searchVo.getStartDate(),searchVo.getEndDate());
        }
        return sysMessageService.page(page, wrapper);
    }


}
